package com.example.novelsys.controller;

import com.example.novelsys.entity.Categories;
import com.example.novelsys.entity.Novel;
import com.example.novelsys.service.CategoriesService;
import com.example.novelsys.service.NovelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {
    @Autowired
    CategoriesService categoriesService;
    @Autowired
    NovelService novelService;

    /*
       登录小说，默认转发首页
     */
    @RequestMapping("/")
    public String welComeNovel(HttpServletRequest req, HttpServletResponse resp) {

        List indexInfo=new ArrayList();
        List rankInfo=new ArrayList();
        //1、获取小说类别
        List<Categories> categoriesList=categoriesService.queryAll();

        //2、获取最新发布的小说
        List<Novel> nowList=novelService.queryNovelByType(1);
        //3、获取热门类别小说
        List<Novel> hotList1=novelService.queryNovelByType(2);
        List<Novel> hotList2=novelService.queryNovelByType(3);
        //4、获取下载排行小说
        List<Novel> downList=novelService.queryNovelByType(4);
        //5、获取阅读排行小说
        List<Novel> readList=novelService.queryNovelByType(5);

        indexInfo.add(categoriesList);
        indexInfo.add(nowList);
        indexInfo.add(hotList1);
        indexInfo.add(hotList2);


        rankInfo.add(downList);
        rankInfo.add(readList);


        req.setAttribute("categoriesList", categoriesList); //单独用于用于菜单栏显示
        req.setAttribute("indexInfo", indexInfo);
        req.setAttribute("rankInfo", rankInfo);
        return "index";

    }
}
